package com.yunshipei.core.utils;

import android.content.Context;

import com.yunshipei.core.common.DataJSCallback;
import com.yunshipei.core.manager.AdapterPkgHandler;
import com.yunshipei.core.manager.UpdateAppsHandler;
import com.yunshipei.core.model.XCloudAppModel;

import org.reactivestreams.Publisher;

import io.reactivex.Flowable;
import io.reactivex.functions.Function;

/**
 * 提供接口给Enterplorer使用
 */
public class YspFunUtils {

    public static void updateXCloudData(Context context, String uuid, String companyId, DataJSCallback dataJSCallback) {
        new UpdateAppsHandler(context, uuid, companyId).start(dataJSCallback);
    }

    //下载某个版本的运行时
    public static Flowable<String> downloadRT(Context context, final String rtVersion) {
        XCloudAppModel xCloudAppModel = new XCloudAppModel();
        xCloudAppModel.setRuntimeVersion(rtVersion);
        xCloudAppModel.setScope("global_runtime_download");
        return new AdapterPkgHandler(context, xCloudAppModel).starOnlyRuntime().flatMap(new Function<XCloudAppModel, Publisher<String>>() {
            @Override
            public Publisher<String> apply(XCloudAppModel xCloudAppModel) throws Exception {
                return Flowable.just(rtVersion);
            }
        });
    }
}
